package com.zh.login.controller;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Description:
 * @ClassName TestVolatile
 * @date: 2021.04.01 16:14
 * @Author: zhanghang
 */
public class TestVolatile {

        public static void main (String[]args){



            System.out.println(DateUtil.dayOfWeek(DateUtil.parse("2021-04-11")));

            String str = "admin";
            String[] split = str.split(",");
            List<String> strings = Arrays.asList(split);
            strings.forEach(System.out::println);
            System.out.println(split.length);

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(DateUtil.parseDate("2021-04-02"));
            calendar.add(Calendar.MONTH, 1);
            calendar.set(Calendar.DATE, 0);
            System.out.println(DateUtil.formatDate(calendar.getTime()));

            Calendar cal = Calendar.getInstance();
            cal.setTime(DateUtil.parseDate("2021-04-02"));
            cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
            System.out.println(DateUtil.formatDate(cal.getTime()));


            System.out.println(DateUtil.beginOfMonth(DateUtil.nextMonth()));
            System.out.println(DateUtil.endOfMonth(DateUtil.nextMonth()));
            //下个月
            DateTime nextMonth = DateUtil.nextMonth();
            System.out.println(nextMonth);

            System.out.println(CustomMadeDateUtil.getNextMonthStartDate());

            System.out.println(CustomMadeDateUtil.getNextMonthEndDate());

            List<DateTime> dateTimes = DateUtil.rangeToList(DateUtil.parse("2021-03-29", DatePattern.NORM_DATE_PATTERN),
                    DateUtil.parse("2021-04-06", DatePattern.NORM_DATE_PATTERN), DateField.DAY_OF_YEAR);
//
            dateTimes.forEach(System.out::println);
            System.out.println(DateUtil.parse("2021-04-06", DatePattern.NORM_DATE_PATTERN));
        }

        private void a (Date date){
            SimpleDateFormat aDateFormat=new SimpleDateFormat("yyyy-MM-dd");
            Calendar c = Calendar.getInstance();
            c.setTime(date);

            //设置为1号,当前日期既为本月第一天
            c.set(Calendar.DAY_OF_MONTH, 1);
            //将小时至0
            c.set(Calendar.HOUR_OF_DAY, 0);
            //将分钟至0
            c.set(Calendar.MINUTE, 0);
            //将秒至0
            c.set(Calendar.SECOND,0);
            //将毫秒至0
            c.set(Calendar.MILLISECOND, 0);
            // 获取本月第一天的时间
        }

    static class HelloThread implements Runnable {

//	private static List<String> list = Collections.synchronizedList(new ArrayList<String>());

        private static CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<>();

        static {
            System.out.println("初始化-----");
            list.add("AA");
            list.add("BB");
            list.add("CC");
        }

        @Override
        public void run() {
            Iterator<String> it = list.iterator();

            while (it.hasNext()) {
                System.out.println(it.next());

                list.add("AA");
            }
        }
    }
}